﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/BMP_TreeGrid.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="Pages_TFunction_Default"  %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">

        ModelName = "TFunctionInfo";
        EmptyRow = [{ GID: "", PGID: "", Code: "", Name: "", URI: "", FType: "", state: "closed", Sequence: ""}]

        var ftypeID = '<% = TFunctionInfo_FType.ClientID %>';

        $(function () {
            $('#' + TreeGridTableID).treegrid({
                title: '权限管理',
                iconCls: 'icon-save',
                width: 650,
                height: 600,
                nowrap: false,
                rownumbers: true,
                animate: true,
                collapsible: true,
                url: vRoot + 'Services/Handler.ashx?Type=' + ModelName + '&PGID=0',
                idField: 'GID',
                treeField: 'Name',
                frozenColumns: [[]],
                columns: [[
					{ field: 'Name', title: '名称', width: 250 },
					{ field: 'Code', title: '编码', width: 300 },
                    { field: 'GID', title: '删除', width: 50, formatter: function (value) {
                        return '<a href="javascript:DeletebyID(\'' + value + '\');">删除</a>';
                    }
                    }
				]],
                onBeforeLoad: function (row, param) {
                    if (row) {
                        $(this).treegrid('options').url = vRoot + 'Services/Handler.ashx?Type=' + ModelName + '&PGID=' + row.GID;
                    } else {
                        $(this).treegrid('options').url = vRoot + 'Services/Handler.ashx?Type=' + ModelName + '&PGID=0';
                    }
                },
                onClickRow: function (node) {
                    OnTFRowClick(node);
                },
                onContextMenu: function (e, row) {
                    e.preventDefault();
                    $(this).treegrid('unselectAll');
                    $(this).treegrid('select', row.GID);
                    $('#menu').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                },
                onLoadSuccess: function () {
                    $('#editTable').show();
                },
                onLoadError: function (e) {
                    alert(e.responseText);
                }
            });
        });

        function OnTFRowClick(row) {
            OnRowClick(row, function () {
                $('#' + ftypeID).val(row.FType);
                OnFTypeChange();
            });

        }

        function InsertTFunction() {
            var fType = $('#' + ftypeID);
            Insert(function (data) {
                data[0].FType = fType.val();
                if (data[0].FType == '3')
                    data[0].state = "open";
                else
                    data[0].state = "closed";
                return true;
            }, function (data, resultData) {
            }, function () {
                fType.val("1");
            });
        }
        function ModifyTFunction() {
            var fType = $('#' + ftypeID);
            Modify(function (node) {
                if (!CheckMyUNQ(node))
                    return false;
                else {
                    node.FType = fType.val();
                    if (node.FType == '3')
                        node.state = "open";
                    else
                        node.state = "closed";
                    return true;
                }
            }, function (node, resultData) {
                if (node.FType == '3')
                    node.state = "open";
                else
                    node.state = "closed";

            }, function () {
                fType.val("1");
            });
        }

        // 修改如果CODE不一致，则验证其唯一性！
        function CheckMyUNQ(node) {
            if (!node)
                return false;
            var code = $('#TFunctionInfo_Code');

            if (node.Code != code.val()) {
                isAdd = true;
                if (!Validate(code))
                    return false;
            }
            return true;
        }
        function OnFTypeChange() {
            var type = $("#" + ftypeID);
            if (type.val() == "2") {
                $("#TFunctionInfo_URI").attr("emp", "true");
                $("#TFunctionInfo_URI").removeAttr("disabled");
            }
            else {
                $("#TFunctionInfo_URI").removeAttr("emp");
                $("#TFunctionInfo_URI").attr("disabled", "disabled");
                $("#TFunctionInfo_URI").val("");
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="Server">
    <form runat="server" id="form1">
    <table>
        <tr style="vertical-align: top">
            <td>
                <table id="treeGridTable">
                </table>
            </td>
            <td>
                <table class="editTable" cellpadding="0" cellspacing="0" id="editTable" style="display: none;">
                    <tr>
                        <th>
                            权限名称：
                        </th>
                        <td>
                            <input id="TFunctionInfo_Name" type="text" des="权限名称" emp="true" /><p id="errorTFunctionInfo_Name">
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            权限编码：
                        </th>
                        <td>
                            <input id="TFunctionInfo_Code" type="text" des="权限编码" emp="true" unq="true" /><p
                                id="errorTFunctionInfo_Code">
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            序号：
                        </th>
                        <td>
                            <input id="TFunctionInfo_Sequence" type="text" des="序号" emp="true" exp="reg_Number" />
                            <p id="errorTFunctionInfo_Sequence">
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            控制点类型：
                        </th>
                        <td>
                            <asp:DropDownList ID="TFunctionInfo_FType" runat="server" onchange="OnFTypeChange();"
                                ClientIDMode="Static">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            URI：
                        </th>
                        <td>
                            <input id="TFunctionInfo_URI" type="text" disabled="disabled" des="URI" /><p id="errorTFunctionInfo_URI">
                            </p>
                        </td>
                    </tr>
                 
                    <tr>
                        <th colspan="2" style="text-align: center; width: 100%;">
                            <input type="button" id="btnInsert" value="添加" onclick="InsertTFunction();" style="width: 70px;" />
                            <input type="button" id="btnModify" value="修改" onclick="ModifyTFunction();" style="width: 70px;" />
                        </th>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div id="menu" class="easyui-menu" style="width: 120px;">
        <div onclick="Delete();">
            删除</div>
    </div>
    </form>
</asp:Content>
